package gui.Vortrag_JFrame;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;



public class GUITest extends JFrame {
	
	private static final long serialVersionUID = 1L;
	
	
	
	// The height of the window in pixels
	public static final int WIDTH = 400;
	// The width of the window in pixels
	public static final int HEIGHT = 300;
	
	static GUITest gui1;
	JDialog dialog;
	
	// The Go Button
	JButton buttongo = new JButton("GO");
	
	ImageIcon ico = new ImageIcon("C:\\Users\\Marvin\\Pictures\\Selfmade\\Hunter Skull\\Dark-Skull-Icon.png");
	
	
	// Constructs a new window with a given title
	public GUITest(String title) {

	
	// Set width and height of the window
	this.setSize(WIDTH, HEIGHT);
	// Close the Programm with the red X
	this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	// Create the panel
	JPanel panel1 = new JPanel();
	// Add a label on the panel
	panel1.add(new JLabel("Press the button"));
	
	JMenuBar menuBar = new JMenuBar();
    menuBar.add(new JMenu("JFrame")).
       add(new JMenuItem("Beenden"));
    panel1.add(menuBar);
    
	
	panel1.add(new JLabel(ico));
	// Add the button "buttongo" on the panel
	panel1.add(buttongo);
	JButton buttonOhh = new JButton("Ohh");
	panel1.add(buttonOhh);
	
	buttonOhh.addActionListener(new ActionListener(){		
		public void actionPerformed(ActionEvent arg0) {
			secJFrame();			
		}
	});	
	
	buttongo.addActionListener(new ActionListener(){		
		public void actionPerformed(ActionEvent arg0) {
			opendialog();			
		}
	});	
		
	
	
	this.add(panel1);
	
	
	// Open the window
	this.setVisible(true);
	
	}
	
	private void opendialog(){
		
		
		dialog = new JDialog(gui1,"Heyho");
		dialog.setVisible(true);
		
		JButton hey = new JButton("Hey");
		dialog.add(hey);
		
		
		hey.addActionListener(new ActionListener(){		
			public void actionPerformed(ActionEvent arg0) {
				go();			
			}
		});	
		
		
//		
//	int wahl =	JOptionPane.showConfirmDialog(null,
//			    "Eggs are not supposed to be green.",
//			    "Inane custom dialog",
//			    JOptionPane.INFORMATION_MESSAGE);
//		System.out.println(wahl);
//		
//		Object[] options = {"Was los?", "HILFE!!", "Das und Gefahr?"};
//		JOptionPane.showOptionDialog(null, "Gefahr!", "Achtung!",
//							JOptionPane.DEFAULT_OPTION, JOptionPane.ERROR_MESSAGE,
//							ico, options, options[1]);
//								
		
		
	}
	
	public void go(){
		
		dialog.setModal(true);
		dialog.setVisible(false);
		dialog.setVisible(true);
		
		
	}
	
	public void secJFrame(){
		
		JFrame secFrame = new JFrame("Zweiter Frame");
		secFrame.setVisible(true);
	}
	
	
	
	// Starts the test application. Creates a new window and displays it
	public static void main(String args[]) {
	// Construct a new window. It is initially invisible
	gui1 =new GUITest("My first GUI Application");

	}
	
}
